<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>快吃管理系统</title>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/main.css"/>
    <script type="text/javascript" src="__PUBLIC__/js/jquery-3.2.1.min.js"></script>
   <script src="__PUBLIC__/js/layer/layer.js"></script>
    <script type="text/javascript" src="__PUBLIC__/js/libs/modernizr.min.js"></script>
</head>
<body>
<div class="container clearfix">
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list" style="background:#fff; border:0px"><i class="icon-font"></i>修改管理员信息</div>
        </div>
        <div class="result-wrap">
            <div class="result-content">
                <form  id="myform">
                    <table class="insert-tab" width="100%">
                        <tbody>   
                        {volist name='data' id='v'}                        
                            <tr>
                                <th><i class="require-red">*</i>用户名：</th>
                                <td>
                                <input name='user_id' style="display:none" type="text" value="{$v.user_id}" />
                                    <input class="common-text required" id="title" name="username" size="85" value="{$v.username}" style="width:300px" type="text">
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>密码：</th>
                                <td>
                                    <input class="common-text required" id="title" name="password" size="85" value="{$v.password}" style="width:300px" type="password">
                                </td>
                            </tr>              
                            <tr>
                                <th><i class="require-red">*</i>姓名：</th>
                                <td>
                                    <input class="common-text required" id="title" name="name" size="85" value="{$v.name}" type="text" style="width:300px">
                                </td>
                            </tr>

                            <tr>
                               <th><i class="require-red">*</i>性别：</th>
                               <td>
                                    <select name="sex" style="width:187px;height:25px; border-color:#ccc; border-radius:5px">
                                        <option value="{$v.sex}">
                                        {if condition="$v.sex eq '1'"}男
                                            {else /} 女
                                            {/if}
                                        </option>
                                        <option value="1">男</option>
                                        <option value="2">女</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>工号：</th>
                                <td>
                                    <input class="common-text required" id="title" name="teacher_id" size="85" value="{$v.teacher_id}" type="text" style="width:300px">
                                </td>
                            </tr>
                            <tr>
                                <th><i class="require-red">*</i>所属食堂：</th>
                                <td>
                                    <select name="restaurant_id" style="width:187px;height:25px; border-color:#ccc; border-radius:5px">
                                        <option value="{$v.restaurant_id}">{$v.restaurant_name}</option>
                                        {volist name='resdata' id='x'}
                                        <option value="{$x.restaurant_id}">{$x.restaurant_name}</option>
                                        {/volist}
                                    </select>
                                </td>
                            </tr>
                           <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary btn6 mr10" value="提交" type="button">
                                    <input class="btn btn6" onclick="back()" value="返回" type="button">
                                </td>
                            </tr>
                            {/volist}
                        </tbody></table>
                </form>
            </div>
        </div>

    </div>
    <!--/main-->
</div>
</body>
<script type="text/javascript">
    function back()
    {
         window.location.href="{:url('UserType/index')}";
    }
    $('.mr10').click(function(){ 
        var username=$('input[name=username]');
        var password=$('input[name=password]');
        var name=$('input[name=name]');
        var sex=$('select[name=sex]');
        var teacher_id=$('inpput[name=teacher_id]');
        var restaurant_id=$('select[name=restaurant_id]');


        if(username.val()=="")
        {
            layer.msg('用户名不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            username.focus();
            return ;
        }

        if(password.val()=="")
        {
            layer.msg('密码不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            password.focus();
            return ;
        }

        if(name.val()=="")
        {
            layer.msg('姓名不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            name.focus();
            return ;
        }

        if(sex.val()=="")
        {
            layer.msg('性别不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            sex.focus();
            return ;
        }

        if(teacher_id.val()=="")
        {
            layer.msg('工号不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            teacher_id.focus();
            return ;
        }

       if(restaurant_id.val()=="")
        {
            layer.msg('所属食堂不能为空', { offset: ['0px', '40%'], icon:7,time:2000});  
            restaurant_id.focus();
            return ;
        }

        var formData = new FormData($("#myform")[0]);//获取表单数据        
          $.ajax({
               url: "{:url('UserType/updatefun')}",//提交地址
               type: 'POST',
               data: formData,
               async: false,
               cache: false,
               contentType: false,
               processData: false,
               success: function (returndata) {
                if(returndata.code=='1'){
                  if(returndata.data!="")
                  layer.msg(returndata.message, { offset: ['0px', '40%'], icon:6,time:1000},function(){
                    window.location.href="{:url('UserType/index')}"; 
                  });
                }
                else
                layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});            
               },
               error: function (returndata) {
                layer.msg(returndata.message, { offset: ['0px', '40%'], icon:5,time:2000});

           }
          });
    });
</script>
</html>